package lg.crypto

class CryptByte(val byte : Short) {

  require(byte >= 0 && byte <= 255, "Byte value must be between 0 and 255")
	
  def +(other : CryptByte) : CryptByte =
    new CryptByte((byte ^ other.byte).asInstanceOf[Short])

  override def toString = (0xff & byte).toString
}

object CryptByte {
  def apply(long : Long) : CryptByte = new CryptByte(long.asInstanceOf[Short])
  def apply(int : Int) : CryptByte = new CryptByte(int.asInstanceOf[Short])
  def apply(short : Short) : CryptByte = new CryptByte(short)
  def apply(char : Char) : CryptByte = new CryptByte(char.asInstanceOf[Short])

  implicit def long2CryptByte(long : Long) = CryptByte(long)
  implicit def int2CryptByte(int : Int) = CryptByte(int)
  implicit def short2CryptByte(short : Short) = CryptByte(short)
  implicit def char2CryptByte(char : Char) = CryptByte(char)
}